package com.minio.it.controller;

import com.minio.it.config.MinioSysFileUploadUtils;
import com.minio.it.model.BaseResponse;
import com.minio.it.model.FileVO;
import com.minio.it.utils.ResultUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/minio/file")
@Tag(name = "Minio-文件管理")
public class FileController {
 
    @Autowired
    private MinioSysFileUploadUtils minioSysFileUploadUtils;
 
    @PostMapping("upload")
    @Operation(summary = "Minio上传文件")
    public BaseResponse<FileVO> upload(@RequestParam("file") MultipartFile file
            , @Schema(description = "包名路径（为：xxx 或者 xxx/xxx 等）") @RequestParam("folder") String folder) throws IOException {
        FileVO upload = minioSysFileUploadUtils.upload(file, folder);
        return ResultUtils.success(upload);
    }
}